#include <stdio.h>

#include "wheel.h"

void gpio_init(uint32_t pin)
{
	/* enable the LEDs GPIO clock */
	rcu_periph_clock_enable(RCU_GPIOD);

	/* configure LED2 GPIO port */
	gpio_mode_set(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, pin);
	gpio_output_options_set(GPIOD, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, pin);
	/* reset LED2 GPIO pin */
	gpio_bit_reset(GPIOD, pin);
}

void gpio_ctl(uint8_t on, uint32_t pin)
{	
	switch(on)
	{
		case 0:
			gpio_bit_reset(GPIOD, pin);
		break;
		case 1:
			gpio_bit_set(GPIOD, pin);
		break;
		default:
			gpio_bit_reset(GPIOD, pin);
		break;
	}
	return ;
}

void wheel_set_scroll(wheel_type *wheel,e_wheel_scroll scroll)
{
	wheel->wheel_scroll = scroll;
	switch(scroll)
	{
		case wheel_stop:
			gpio_ctl(0,wheel->ios[0]);
			gpio_ctl(0,wheel->ios[1]);
		break;
		case wheel_go:
			gpio_ctl(1,wheel->ios[0]);
			gpio_ctl(0,wheel->ios[1]);
		break;
		case wheel_back:
			gpio_ctl(0,wheel->ios[0]);
			gpio_ctl(1,wheel->ios[1]);
		break;
		case wheel_mini:
		case wheel_max:
		default:
			gpio_ctl(1,wheel->ios[0]);
			gpio_ctl(1,wheel->ios[1]);
		break;
	}
}

